#include #include #include using namespace std; struct Pixel { unsigned char blue; unsigned char green; unsigned char red; void display() { //cout << "(" << (int)red << "," << (int)green << "," << (int)blue << ")"; if(blue > red && blue > green) { cout << "B"; } else if(red > green) { cout << "R"; } else { cout << "G"; } } }; struct FileStruct { char type[3]; FileStruct() { type[2] = '\0'; } }; void main() { FileStruct fs; //fs.type[2] = '\0'; cout << (ios_base::in | ios_base::out |ios_base::binary) << endl; cout << ios_base::in << endl; cout << ios_base::out << endl; cout << ios_base::binary << endl; fstream fin("bflag.bmp", ios_base::in | ios_base::out |ios_base::binary); char bfType[3] = {0}; unsigned int bfSize; unsigned int biWidth; unsigned int biHeight; fin.read(bfType,2); fin.read((char*)&bfSize,4); //fin.seekg(18, ios_base::cur); fin.seekg(18, ios_base::beg); //fin.seekg(18, ios_base::end); fin.read((char*)&biWidth,4); fin.read((char*)&biHeight,4); //swap(biWidth, biHeight); //fin.seekp(18, ios_base::beg); //fin.write((char*)&biHeight,4); //fin.write((char*)&biWidth,4); cout << bfType << endl; cout << bfSize << endl; cout << biWidth << endl; cout << biHeight << endl; fin.seekg(54, ios_base::beg); //for(int i = 0; i < biWidth * biHeight; i++) //{ // Pixel p; // fin.read((char*)&p,3); // //fin.read((char*)&p.blue,1); // //fin.read((char*)&p.green,1); // //fin.read((char*)&p.red,1); // p.display(); //} for(int i = 0; i < biHeight; i++) { for(int j= 0 ; j < biWidth; j++) { Pixel p; fin.read((char*)&p,3); p.display(); } cout << endl; } fin.close(); }